using System;
using System.Collections.Generic;
using System.Text;

using System.IO;

namespace MD5
{
    class SUPPORT
    {
        public static byte[] String2ArrByte(String data) { return Encoding.ASCII.GetBytes(data); }

        public static String ArrByte2String(byte[] data) { return Encoding.ASCII.GetString(data); }

        public static byte[] HexString2ArrByte(String data)
        {
            byte[] result = new byte[data.Length / 2];
            for (int i = 0; i < data.Length; i += 2)
                result[i / 2] = Convert.ToByte(data.Substring(i, 2), 16);
            return result;
        }

        public static String ArrByte2HexString(byte[] data)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
                result.Append(data[i].ToString("X2"));
            return result.ToString();
        }

        public static byte[] File2ArrByte(String fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();
            return data;
        }

        public static void String2File(String fileName, String data)
        {
            StreamWriter sw = new StreamWriter(fileName);
            sw.Write(data);
            sw.Close();
        }
    }
}
